import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import org.json.JSONException;
import org.json.JSONObject;


public class Connection {
	
	static String makeRequest(String address)
	{
		String msg = "";
		
	       try
	        {
	            URL url = new URL(address);

	            // Get an input stream for reading
	            InputStream in = url.openStream();

	            // Create a buffered input stream for efficency
	            BufferedInputStream bufIn = new BufferedInputStream(in);

	            // Repeat until end of file
	            for (;;)
	            {
	                int data = bufIn.read();
	                // Check for EOF
	                if (data == -1)
	                    break;
	                else
	                	msg+=(char)data;
	            }
	        }
	        catch (MalformedURLException mue)
	        {
	            return error("Invalid URL");
	        }
	        catch (IOException ioe)
	        {
	            return error("I/O Error - " + ioe);
	        }
	        
			try {
				JSONObject obj = new JSONObject(msg);	
			} catch (JSONException e) {
				return error(e.getMessage());
			}
		return msg;
	}
	
	static String error(String msg)
	{
		return "{\"error\":\" "+msg +" \"}";	
	}
}
